package com.situ.day8;

import java.util.Scanner;

import org.junit.Test;

public class HomeWork {

	@Test
	public void test1() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一串字符：");
		String str = scanner.nextLine();
		int start = 0;
		int end = str.length() - 1;
		if (str == null || str.equals("")) {
			return;
		}
		while (start < str.length()) {
			if (str.charAt(start) == ' ') {
				start++;
			} else {
				break;
			}
		}
		while (end > 0 && start <= end) {
			if (str.charAt(end) == ' ') {
				end--;
			} else {
				break;
			}
		}
//		if (start >= str.length()) {
//			start = 0;
//		}
//		if (end < 0) {
//			end = str.length() - 1;
//		}

		String string = str.substring(start, end + 1);
		System.out.println(string);
	}

	@Test
	public void test12() {
		Scanner scanner = new Scanner(System.in);
		System.out.println("请输入一串字符：");
		String str = scanner.nextLine();
		int start = 0;
		int end = str.length() - 1;
		if (str == null || str.equals("")) {
			return;
		}
		while ((start <= end) && (str.charAt(start) == ' ')) {
			start++;
		}
		while ((start <= end) && (str.charAt(end) == ' ')) {
			end--;
		}
		String string = str.substring(start, end + 1);
		System.out.println(string);
	}

	@Test
	public void test2() {
		String str = new String("I Love Java !");
		char[] array = str.toCharArray();
		for (int i = 0; i < array.length; i++) {
			if (array[i] > 'A' && array[i] < 'Z') {
				array[i] = (char) (array[i] + 32);
			}
		}
		String string = new String(array);
		System.out.println(string);
	}

	// 第二题第二种方法
	@Test
	public void test2_2() {
		String str = new String("I Love Java !");
		String newStr = str.toLowerCase();
		System.out.println(newStr);
	}

	@Test
	public void test3() {
		String str = new String("this is my homework! I must finish it!");
		String[] array = str.split(" ");
		System.out.println(array.length);
	}
}
